package org.jfsm.demo.ccounter.cnt;

import org.jfsm.core.ConcurrentFSMContext;
import org.jfsm.core.FSMException;
import org.jfsm.demo.ccounter.CntController;
import org.jfsm.demo.ccounter.echo.EchoContext;

public class CntContext extends ConcurrentFSMContext {

    EchoContext[] server;

    long msgCount;
    long starttime;

    int[] counter;

    CntContext() throws FSMException {
        int numServers = CntController.numServers;
        server = new EchoContext[numServers];
        counter = new int[numServers];
    }

    void display() {
        long endtime = System.nanoTime();
        long starttime = this.starttime;
        long speed = 0;

        if (endtime > starttime) {
            speed = (msgCount * 1000000l) / (endtime - starttime);
        }
        System.out.println(String.valueOf(speed) + " k ping /s");
    }

    @Override
    public String toString() {
        return "counter";
    }

}
